package T14;
import java.util.Calendar;

 class Car {
    private String brand;
    private double price;
    private String color;
    private Calendar date;

    // 无参构造方法，调用带参构造方法初始化变量
    public Car() {
        this("未知品牌", 0.0, "未知颜色", Calendar.getInstance());
    }

    // 带参构造方法
    public Car(String brand, double price, String color, Calendar date) {
        this.brand = brand;
        this.price = price;
        this.color = color;
        this.date = date;
    }

    // getBrand方法
    public String getBrand() {
        return brand;
    }

    // setBrand方法
    public void setBrand(String brand) {
        this.brand = brand;
    }

    // getPrice方法
    public double getPrice() {
        return price;
    }

    // setPrice方法
    public void setPrice(double price) {
        this.price = price;
    }

    // getColor方法
    public String getColor() {
        return color;
    }

    // setColor方法
    public void setColor(String color) {
        this.color = color;
    }

    // getDate方法
    public Calendar getDate() {
        return date;
    }

    // setDate方法
    public void setDate(Calendar date) {
        this.date = date;
    }

    // 重写toString方法显示所有成员信息
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("品牌：").append(brand).append("\n");
        sb.append("颜色：").append(color).append("\n");
        sb.append("价格：").append(price).append("万").append("\n");
        sb.append("销售日期：");
        int year = date.get(Calendar.YEAR);
        int month = date.get(Calendar.MONTH) + 1;
        int day = date.get(Calendar.DAY_OF_MONTH);
        sb.append(year).append("年").append(String.format("%02d", month)).append("月").append(String.format("%02d", day)).append("日");
        return sb.toString();
    }
}
public class CarDemo {
    public static void main(String[] args) {
        // 使用无参构造方法创建Car对象car1
        Car car1 = new Car();
        // 设置car1的属性
        car1.setBrand("奥拓");
        car1.setColor("土豪金");
        car1.setPrice(3.8);
        Calendar calendar1 = Calendar.getInstance();
        calendar1.set(2022, Calendar.MAY, 15);
        car1.setDate(calendar1);
        System.out.println(car1.toString());
        System.out.println("-----------------------------");

        // 使用带参构造方法创建Car对象car2
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(2022, Calendar.MAY, 15);
        Car car2 = new Car("奥迪", 38.0, "黑色", calendar2);
        System.out.println(car2.toString());
    }
}
